package org.deschutter.scans.jumpgate;

import org.deschutter.Constants;
import org.deschutter.Queries;
import org.deschutter.scans.Scan;
import org.deschutter.constants.Config;
import org.deschutter.exceptions.AddActionException;
import org.deschutter.exceptions.DeriveIntelException;
import org.deschutter.exceptions.PlanetNotFoundException;
import org.hibernate.Session;

import java.math.BigDecimal;
import java.util.HashMap;

/**
 * User: Berten De Schutter
 * Date: 02-Jul-2009
 * Time: 16:36:33
 */
public class Friendly extends Fleet {
    public Friendly(String x, String y, String z, Integer eta, Integer amount, String fleetname, Scan scan) {
        super(x, y, z, eta, amount, fleetname,scan);
    }

    public String toString() { // purely for testing purposes
        return "+ Defense " + getX() + ":" + getY() + ":" + getZ() + " " + getFleetname() + " " + getEta() + " " + getAmount();
    }

    @Override
    public void deriveIntel() throws DeriveIntelException {
        /*
          If a planet (x,y,z) defends another planet, that is not in their galaxy
          The chances are great they are in the same alliance.
        */
        BigDecimal bdeta = new BigDecimal(getEta());
        //try {

        //    HashMap<String, String> planetruler = Queries.getPlanetRulerFromCoords(getScan().getX(), getY(), getZ(), tick);
        //    HashMap<String, String> planetrulerTarget = Queries.getPlanetRulerFromCoords(xTarget, yTarget, zTarget, tick);
          //  Queries.addAction(planetruler.get("planetname"), planetruler.get("rulername"), Constants.DEFENCE_ACTION, scanId, tick.add(bdeta), planetrulerTarget.get("planetname"), planetrulerTarget.get("rulername"));
            org.deschutter.hibernate.Planets planet = getScan().getPlanet();
           // org.deschutter.hibernate.Planets planetTarget = 

       /* } catch (PlanetNotFoundException e) {
            throw new DeriveIntelException("Could not Derive intel for: " + getX() + ":" + getY() + ":" + getZ() + " scan id:" + scanId + " Tick: " + tick + ". " + e.getError());
        } catch (AddActionException e) {
            throw new DeriveIntelException("Could not Derive intel for: " + getX() + ":" + getY() + ":" + getZ() + " scan id:" + scanId + " Tick: " + tick + ". " + e.getError());
        }*/
    }

    @Override
    public BigDecimal getFleetType() {
        return Config.JGP_DEFEND_TYPE;
    }
}
